package com.dsteiner.gwt.cafeteriasophia.server;

import com.dsteiner.gwt.cafeteriasophia.client.rpc.DataService;
import com.dsteiner.widgets.client.domain.ModelObject;
import com.dsteiner.widgets.client.rpc.CrudResult;
import com.dsteiner.widgets.server.BaseDataServiceImpl;
import com.dsteiner.widgets.server.dao.BaseDataDao;
import com.dsteiner.widgets.server.dao.jdo.BaseDataDaoJdo;

/**
 * The server side implementation of the RPC service.
 */
@SuppressWarnings("serial")
public class DataServiceImpl extends BaseDataServiceImpl implements DataService {
	private BaseDataDao dataDao = new BaseDataDaoJdo();

	public DataServiceImpl() {
		setDataDao(dataDao);
//		String url = getThreadLocalRequest().getRequestURI();
//		if("".equals(url)){
////			ApiProxy.setEnvironmentForCurrentThread(new TestEnvironment());
////			ApiProxy.setDelegate(new ApiProxyLocalImpl(new File(".")){});
//		}
	}
	
	public CrudResult createModelObject(ModelObject modelObject) {
		ModelObject save = dataDao.save(modelObject);
		CrudResult crudResult = new CrudResult();
//		crudResult.setModelObject(save);
		return crudResult;
	}

	public CrudResult deleteObject(ModelObject modelObject) {
		dataDao.deleteObject(modelObject);
		CrudResult crudResult = new CrudResult();
		crudResult.setModelObject(modelObject);
		return crudResult;
	}

}
